package com.qfedu.controller;

import com.alibaba.fastjson.JSON;
import com.qfedu.entity.Managers;
import com.qfedu.service.ManagerService;
import com.qfedu.service.impl.ManagerServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @version v1.0
 * @Date 2023/10/9 18:20
 * @Author DARKER
 * @Email 1402216045@qq.com
 */
@WebServlet("/managers/list.do")
public class ManagerListController extends HttpServlet {
    private ManagerService service = new ManagerServiceImpl();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        List<Managers> all = service.findAll();
        req.setCharacterEncoding("utf-8");
        resp.setContentType("application/json;charset=utf-8");
        resp.setCharacterEncoding("utf-8");
        String json = JSON.toJSONString(all);
        resp.getWriter().write(json);


    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
